import type { PluginOption } from 'vite';

import path from 'node:path';

// vite.config.ts
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons';

export interface SvgIconsPluginOptions {
  /**
   * 图标文件夹路径
   * @default 'src/assets/icons'
   */
  iconDirs?: string[];
  /**
   * symbolId格式
   * @default 'icon-[dir]-[name]'
   */
  symbolId?: string;
}

export function viteSvgIconsPlugin(
  options: SvgIconsPluginOptions = {},
): PluginOption {
  const {
    iconDirs = [path.resolve(process.cwd(), 'src/assets/icons')],
    symbolId = 'icon-[dir]-[name]',
  } = options;

  return createSvgIconsPlugin({
    customDomId: '__svg__icons__dom__',
    iconDirs,
    inject: 'body-first',
    symbolId,
  });
}
